
print('Im HERE!!')

function klHttpGet(url, user_cb)
    klHttpRequest("GET", url, user_cb)
end

function klHttpPost(url, body, user_cb)
    klHttpRequest("POST", url, user_cb)
end

-- ================================================================
function klBPHttpGetThenModifyText(url, textComp)
    klHttpGet(url, function(code, body)
        print(textComp)
        textComp:SetText(body)
    end)
end

-- ================================================================

-- TODO: body
function klHttpRequest(get_post, url, user_cb)
    local req = FHttpModule.Get():CreateRequest()
    req:SetURL(url)
    req:SetVerb(get_post)
    req:SetHeader("User-Agent", "X-UnrealEngine")

    req:OnProcessRequestComplete():Bind(function(req,resp,ret)
        local body = resp:GetBody()
        print("http complete", ret, resp:GetResponseCode(), body)
        if user_cb then
            pcall(user_cb, tonumber(resp:GetResponseCode()), body)
        end
    end)
    
    print("http test begin", url)
    req:ProcessRequest()
end